package com.duoduo.demo.springnoxml.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.duoduo.demo.springnoxml.dao.HelpTopicDao;
import com.duoduo.demo.springnoxml.model.HelpTopic;
import com.duoduo.demo.springnoxml.vo.HelpTopicVO;

@Service
public class HelpTopicService {

	@Autowired
	private HelpTopicDao helpTopicDao;

	public List<HelpTopicVO> listAll() {
		return fromEntityList(helpTopicDao.listAll());
	}

	public List<HelpTopicVO> listByCategory(int categoryId) {
		return fromEntityList(helpTopicDao.listByCategory(categoryId));
	}

	public List<HelpTopicVO> listByKeyword(int keywordId) {
		return fromEntityList(helpTopicDao.listByKeyword(keywordId));
	}

	private List<HelpTopicVO> fromEntityList(List<HelpTopic> entityList) {
		List<HelpTopicVO> voList = new ArrayList<HelpTopicVO>(0);
		if (CollectionUtils.isEmpty(entityList)) {
			return voList;
		}

		for (HelpTopic entity : entityList) {
			voList.add(HelpTopicVO.fromEntity(entity));
		}
		return voList;
	}
}
